//
// Created by lyc on 2025/2/24.
//
#include "iostream"
using namespace std;
struct Student{
    long ID;
    int testSeat;
    int examSeat;
}SeatInfo;

long *getSeatNumber(Student *student, int testSeat){
    /**
     * function: 查询给定testSeat, 查询对应的examSeat
     * param: 总数据库student, 待查询 testSeat
     * return: result[2]数组,首元素：ID,sec 元素: examSeat
     */
    long *result = new long[2];     //这里一定不能用普通数组定义方式，因为传出去的是首元素地址
                                    //而这里定义的局部变量在函数结束后释放，导致地址对应位置数据为null
                                    //但是堆上定义的数据要记得释放
    for(int i =0; student[i].ID != 0; i++ ){
        if(testSeat == student[i].testSeat) {
            result[0] = student[i].ID;
            result[1] = student[i].examSeat;
            return result;
        }
    }
    return nullptr;
}


void algorithm6(){
    int scaleOfDatabase;
    cin >> scaleOfDatabase;

    // 输入原始数据，相当于创建数据库
    Student student[scaleOfDatabase];
    for(int j = 0; j < scaleOfDatabase; j++){
        cin >> student[j].ID
            >> student[j].testSeat
            >> student[j].examSeat;
    }

    int numberOfSearch;
    cin >> numberOfSearch;

    int testSeat;
    long *result;
    long resultQueue[numberOfSearch][2];

    // 查询，存储结果
    for(int x = 0; x < numberOfSearch; x++){
        cin >> testSeat;


        result = getSeatNumber(student, testSeat);
        if(result != nullptr) {
            resultQueue[x][0] = result[0];
            resultQueue[x][1] = result[1];
        }
        else{
            resultQueue[x][0] = 0;
            resultQueue[x][1] = 0;
        }
        delete[] result;
    }


    // 输出结果，如果结果为0， 打印404报错信息
    for (int y = 0; y < numberOfSearch; y++) {
        if(resultQueue[y][0] != 0)
        cout << resultQueue[y][0] << " " << resultQueue[y][1] << endl;
        else cout << "404 not found!" << endl;
    }

}